@extends('common.base-master')

@section('html-head')
    <link rel="stylesheet" href="{{url('css/swiper.min.css')}}">
    <link href="{{url('css/mui.picker.css')}}" rel="stylesheet" />
    <script src="{{url('js/swiper.jquery.min.js')}}"></script>
    <script src="{{url('js/lCalendar.js')}}"></script>
    <link rel="stylesheet" href="{{url('css/lCalendar.css')}}">

@endsection

@section('html-body')
    <p class="pay"><button>微信支付</button></p>

    <script>
        $(function() {
            function WXPayment(configJSON) {
                if (typeof WeixinJSBridge === 'undefined') {
                    alert('请在微信在打开页面！');
                    return false;
                }
                WeixinJSBridge.invoke('getBrandWCPayRequest', configJSON, function (res) {
                    switch (res.err_msg) {
                        case 'get_brand_wcpay_request:cancel':
                            alert('用户取消支付！');
                            break;
                        case 'get_brand_wcpay_request:fail':
                            alert('支付失败！（' + res.err_desc + '）');
                            break;
                        case 'get_brand_wcpay_request:ok':
                            setRecordToAdvertiserInfo();
                            break;
                        default:
                            alert(JSON.stringify(res));
                            break;
                    }
                });
            }

            $('.pay button').click(function(){
                    $.ajax({
                        type: "get",
                        url: '{{route('Api.Wechat.pay')}}',
                        dataType: "json",
                        success: function (obj) {
                            if (obj.level == "success") {
                                WXPayment(obj.data);
                            }
                        },
                        error: function (obj) {
                            var datajson = obj.responseJSON;
                            noty({text:datajson.message,type:datajson.level,timeout:600});
                        }
                    });
            });
        });
    </script>
@endsection